# -*- coding: utf-8 -*-
from match import Extractor
import regex as re
import os
from storage.digit_util import *


class MoneyExtractor(Extractor):

    @staticmethod
    def is_my_job(file_path):
        return True

    @staticmethod
    def extract(text):
        result = {}
        Regx = re.compile("(([1-9]\\d*[\\d,，]*\\.?\\d*)|(0\\.[0-9]+))(元|百万|万元|亿元|万|亿)")
        temp_result_set = [term for term in re.split(r'[""“”;,!:：；，。！]', text) if '元' in term]
        is_digit = re.compile('-?\d+\.?\d*e?-?\d*?')
        result_set = [_ for _ in temp_result_set if is_digit.findall(_)]
        money_result = [Regx.search(term).group() for term in result_set if Regx.search(term) is not None]
        if money_result is not None:
            result["涉及金额"] = str(get_max_money(money_result)) + "元"
        return result


if __name__ == '__main__':
    print(MoneyExtractor.extract("上诉人王建军参与实施抢夺犯罪两起涉案14263万元，原审被告人王今利参与实施抢夺犯罪三起，涉案2423元，"
                                 "且王今利系累犯，综合考虑二人诈骗8亿元相关犯罪情节，原判对二人量刑"
                                 "显失均衡，应予纠正，故对其该节上诉31.31万元理由及其辩护人相关辩护意见，予以采纳。"))
